﻿using System;

namespace Itfort.UserCenter
{
	/// <summary>
	/// 实体转换类
	/// </summary>
	public static class EntityConvert
	{
		#region 将简单实体转换成数据实体

		/// <summary>
		/// 将User转换EdmEntities.User。
		/// </summary>
		public static User ToUser(this EdmEntities.User edmEntity)
		{
			User entity = new User();	
			entity.Id = edmEntity.Id;
			entity.UserName = edmEntity.UserName;
			entity.Password = edmEntity.Password;
			entity.PasswordSalt = edmEntity.PasswordSalt;
			entity.Email = edmEntity.Email;
			entity.Mobile = edmEntity.Mobile;
			entity.LoginViaEmail = edmEntity.LoginViaEmail;
			entity.LoginViaMobile = edmEntity.LoginViaMobile;
			entity.Nickname = edmEntity.Nickname;
			entity.CreationTime = edmEntity.CreationTime;
			entity.CreationIP = edmEntity.CreationIP;
			return entity;
		}

		/// <summary>
		/// 将UserStatus转换EdmEntities.UserStatus。
		/// </summary>
		public static UserStatus ToUserStatus(this EdmEntities.UserStatus edmEntity)
		{
			UserStatus entity = new UserStatus();	
			entity.UserId = edmEntity.UserId;
			entity.LastLoginTime = edmEntity.LastLoginTime;
			entity.LastLoginIP = edmEntity.LastLoginIP;
			entity.FailedLoginAttempts = edmEntity.FailedLoginAttempts;
			entity.LastFailedLoginTime = edmEntity.LastFailedLoginTime;
			return entity;
		}

		/// <summary>
		/// 将UserSetting转换EdmEntities.UserSetting。
		/// </summary>
		public static UserSetting ToUserSetting(this EdmEntities.UserSetting edmEntity)
		{
			UserSetting entity = new UserSetting();	
			entity.K = edmEntity.K;
			entity.V = edmEntity.V;
			return entity;
		}

		#endregion

		#region 将简单实体转换成数据实体

		/// <summary>
		/// 将EdmEntities.User转换User。
		/// </summary>
		public static EdmEntities.User ToEdmUser(this User entity)
		{
			EdmEntities.User edmEntity = new EdmEntities.User();	
			edmEntity.Id = entity.Id;
			edmEntity.UserName = entity.UserName;
			edmEntity.Password = entity.Password;
			edmEntity.PasswordSalt = entity.PasswordSalt;
			edmEntity.Email = entity.Email;
			edmEntity.Mobile = entity.Mobile;
			edmEntity.LoginViaEmail = entity.LoginViaEmail;
			edmEntity.LoginViaMobile = entity.LoginViaMobile;
			edmEntity.Nickname = entity.Nickname;
			edmEntity.CreationTime = entity.CreationTime;
			edmEntity.CreationIP = entity.CreationIP;
			return edmEntity;
		}

		/// <summary>
		/// 将EdmEntities.UserStatus转换UserStatus。
		/// </summary>
		public static EdmEntities.UserStatus ToEdmUserStatus(this UserStatus entity)
		{
			EdmEntities.UserStatus edmEntity = new EdmEntities.UserStatus();	
			edmEntity.UserId = entity.UserId;
			edmEntity.LastLoginTime = entity.LastLoginTime;
			edmEntity.LastLoginIP = entity.LastLoginIP;
			edmEntity.FailedLoginAttempts = entity.FailedLoginAttempts;
			edmEntity.LastFailedLoginTime = entity.LastFailedLoginTime;
			return edmEntity;
		}

		/// <summary>
		/// 将EdmEntities.UserSetting转换UserSetting。
		/// </summary>
		public static EdmEntities.UserSetting ToEdmUserSetting(this UserSetting entity)
		{
			EdmEntities.UserSetting edmEntity = new EdmEntities.UserSetting();	
			edmEntity.K = entity.K;
			edmEntity.V = entity.V;
			return edmEntity;
		}

		#endregion
	}
}